import { http } from "../http";
import { QuotaType } from "./quota";

const baseUrl = "/api/template";
export interface TemplateType {
  id: string;
  name: string;
  createUserCode?: string | null;
  createUserName?: string | null;
  note?: string | null;
  defaultTemplate?: boolean;
  createTime?: string;
}
export interface GetTemplateListQueryType {
  name?: string | null;
  currentPage?: number | null;
  numPerPage?: number | null;
}

export interface GetTemplateListResponseType {
  list: TemplateType[];
  currentPage: number;
  numPerPage: number;
  totalCount: number;
}

export interface AddOrUpdateTemplateQueryType {
  id?: string | null;
  name: string | null;
  createUserCode?: string | null;
  note?: string | null;
  quotaList?: QuotaType[] | null;
}

export interface DeleteTemplateQueryType {
  templateIds: string[] | null;
}

export interface CopyTemplateQueryType {
  templateIds: string[] | null;
}

export interface GetTemplateDetailQueryType {
  templateId: string;
}
export interface GetTemplateDetailResponseType {
  id: string;
  name: string;
  createUserCode?: string | null;
  createUserName?: string | null;
  note?: string | null;
  defaultTemplate?: boolean;
  createTime?: string;
  quotaList?: QuotaType[] | null;
}

// 获取模板列表
export const getTemplateListAPI = (params: GetTemplateListQueryType) => {
  return http.post(`${baseUrl}/getTemplateList`, params);
};
// 添加或修改模板
export const addOrUpdateTemplateAPI = (
  params: AddOrUpdateTemplateQueryType
) => {
  return http.post(`${baseUrl}/addOrUpdateTemplate`, params);
};
// 删除模板
export const deleteTemplateAPI = (params: DeleteTemplateQueryType) => {
  return http.post(`${baseUrl}/deleteTemplate`, params);
};
// 复制模板
export const copyTemplateAPI = (params: CopyTemplateQueryType) => {
  return http.post(`${baseUrl}/copyTemplate`, params);
};
// 获取模板详情
export const getTemplateDetailAPI = (params: GetTemplateDetailQueryType) => {
  return http.post(`${baseUrl}/getTemplateDetail`, params);
};
